package com.ruoyi.system.service.aid.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.aid.AidAllocationMapper;
import com.ruoyi.system.domain.aid.AidAllocation;
import com.ruoyi.system.service.aid.IAidAllocationService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;

/**
 * 物资分配Service业务层处理
 * 
 * @author ruoyi
 */
@Service
public class AidAllocationServiceImpl implements IAidAllocationService {
    @Autowired
    private AidAllocationMapper aidAllocationMapper;

    /**
     * 查询物资分配列表
     */
    @Override
    public List<AidAllocation> selectAidAllocationList(AidAllocation aidAllocation) {
        return aidAllocationMapper.selectAidAllocationList(aidAllocation);
    }

    /**
     * 查询物资分配详细
     */
    @Override
    public AidAllocation selectAidAllocationById(Long allocationId) {
        return aidAllocationMapper.selectAidAllocationById(allocationId);
    }

    /**
     * 新增物资分配
     */
    @Override
    public int insertAidAllocation(AidAllocation aidAllocation) {
        aidAllocation.setCreateTime(DateUtils.getNowDate());
        aidAllocation.setCreateBy(SecurityUtils.getUsername());
        return aidAllocationMapper.insertAidAllocation(aidAllocation);
    }

    /**
     * 修改物资分配
     */
    @Override
    public int updateAidAllocation(AidAllocation aidAllocation) {
        aidAllocation.setUpdateTime(DateUtils.getNowDate());
        aidAllocation.setUpdateBy(SecurityUtils.getUsername());
        return aidAllocationMapper.updateAidAllocation(aidAllocation);
    }

    /**
     * 批量删除物资分配
     */
    @Override
    public int deleteAidAllocationByIds(Long[] allocationIds) {
        return aidAllocationMapper.deleteAidAllocationByIds(allocationIds);
    }

    /**
     * 删除物资分配信息
     */
    @Override
    public int deleteAidAllocationById(Long allocationId) {
        return aidAllocationMapper.deleteAidAllocationById(allocationId);
    }

    /**
     * 根据捐赠ID查询分配记录
     */
    @Override
    public List<AidAllocation> selectAidAllocationByDonationId(Long donationId) {
        return aidAllocationMapper.selectAidAllocationByDonationId(donationId);
    }

    /**
     * 根据需求ID查询分配记录
     */
    @Override
    public List<AidAllocation> selectAidAllocationByDemandId(Long demandId) {
        return aidAllocationMapper.selectAidAllocationByDemandId(demandId);
    }

    /**
     * 根据状态查询分配记录
     */
    @Override
    public List<AidAllocation> selectAidAllocationByStatus(String status) {
        return aidAllocationMapper.selectAidAllocationByStatus(status);
    }

    /**
     * 审核物资分配
     * 
     * @param aidAllocation 物资分配
     * @return 结果
     */
    @Override
    public int verifyAidAllocation(AidAllocation aidAllocation) {
        aidAllocation.setVerifyTime(DateUtils.getNowDate());
        aidAllocation.setVerifyBy(SecurityUtils.getUsername());
        aidAllocation.setUpdateTime(DateUtils.getNowDate());
        aidAllocation.setUpdateBy(SecurityUtils.getUsername());
        return aidAllocationMapper.updateAidAllocation(aidAllocation);
    }
} 